From 5fe2d3317d60411970e662d62ffc05fe5eac7319 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Thu, 4 Aug 2022 14:05:09 +0200 Subject: [PATCH] Fix horizontal off-by-one error Delay increasing width used by columns until we know that we have to do so because we have determined that there is enough room to add an additional column and a space between the last two columns. If we don't do that, then we can easily get an off-by-one error. If docstrings are shown and the window is narrow, then it is likely that we end up using the maximal width. If we then add one to the actual width and later compare that again with the maximal width, then that is too width. --- which-key.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/which-key.el b/which-key.el index 8162d207f70..9d5e403f6d8 100644 --- a/which-key.el +++ b/which-key.el @@ -1877,7 +1877,7 @@ that width." (which-key--max-len col-keys 2 which-key-min-column-description-width))) - (col-width (+ 1 col-key-width col-sep-width col-desc-width)) + (col-width (+ col-key-width col-sep-width col-desc-width)) (col-format (concat "%" (int-to-string col-key-width) "s%s%-" (int-to-string col-desc-width) "s"))) (cons col-width @@ -1915,10 +1915,10 @@ as well as metadata." (while (and cols-w-widths (or (null which-key-max-display-columns) (< n-columns which-key-max-display-columns)) - (<= (+ (caar cols-w-widths) page-width) avl-width)) + (<= (+ page-width 1 (caar cols-w-widths)) avl-width)) (setq col (pop cols-w-widths)) (push (cdr col) page-cols) - (cl-incf page-width (car col)) + (cl-incf page-width (1+ (car col))) (cl-incf n-keys (length (cdr col))) (cl-incf n-columns)) (push (which-key--join-columns page-cols) pages) -- 2.30.2